<template>
  <div >
    <router-link tag="div" to="/" class="header-abc" >
      <span class="iconfont abc-back">&#xe658;</span>
    </router-link>
    <div class="header" v-show="!ifshow" :style="opacitystyle" >
      <router-link to="/" >
        <span class="iconfont backicon">&#xe658;</span>
      </router-link>
      <span>景点详情</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'detailheader',
  props: {
    scrolltop: Number
  },
  data () {
    return {
      ifshow: true,
      opacitystyle: {
        opacity: 0
      }
    }
  },
  watch: {
    scrolltop () {
      this.handleScroll()
    }
  },
  methods: {
    handleScroll () {
      const top = this.scrolltop
      if (top > 60) {
        this.ifshow = false
        let opacity = top / 120
        opacity = opacity > 1 ? 1 : opacity
        this.opacitystyle.opacity = opacity
      } else {
        this.ifshow = true
      }
    }
  },
  mounted () {
    // window.addEventListener('scroll', this.handleScroll)
  }
}
</script>

<style scoped>
  .header{
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: #00d3d3;
    color:#fff;
    line-height:50px;
    justify-content: center;
  }
  .backicon{
    font-size: 32px;
    position: absolute;
    left: 0;
    color: #fff;
  }
  .header-abc{
    position: absolute;
    top: 10px;
    left: 10px;
    background: #000;
    opacity: 0.6;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .abc-back{
    font-size: 32px;
    color: #fff;
  }
</style>
